package com.exam.security.util;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * ThreadLocal 获取用户信息
 */
public class GetTokenInfoUtil {
    /**
     * 获取登陆的用户名
     */
    public static String getUsername() {
        UserDetails principal = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        String username = principal.getUsername();
        return username;
    }
}
